*This file creates above median event study figures D.6-D.7

*Import industry data
use  "$path/industry_data.dta", clear

forvalues x=34(1)70{
	gen repam19`x'=ydum19`x'*d2_s
	}
forvalues x=34(1)70{
	gen repal19`x'=ydum19`x'*d1_s
	}
	
local joku "1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970"

foreach l of local joku {
label var repam`l'  `l'
}

local repaflexible1 " repam1934 repam1935 repam1936 repam1937 repam1938 repam1939 repam1940 repam1941 repam1942 repam1944 repam1945 repam1946 repam1947 repam1948 repam1949 repam1950 repam1951 repam1952 repam1953 repam1954 repam1955 repam1956 repam1957 repam1958 repam1959 repam1960 repam1961 repam1962 repam1963 repam1964 repam1965 repam1966 repam1967 repam1968 repam1969 repam1970  "
local repaflexible2 " repal1934 repal1935 repal1936 repal1937 repal1938 repal1939 repal1940 repal1941 repal1942 repal1944 repal1945 repal1946 repal1947 repal1948 repal1949 repal1950 repal1951 repal1952 repal1953 repal1954 repal1955 repal1956 repal1957 repal1958 repal1959 repal1960 repal1961 repal1962 repal1963 repal1964 repal1965 repal1966 repal1967 repal1968 repal1969 repal1970  "
tempfile p31 p32


parmby  "reghdfe lnlabor_all  `repaflexible1' `repaflexible2'    , absorb(year isic $highcontrols) vce(cluster isic)", lab saving(`"`p32'"',replace) idn(1) ids(Unadjusted) 


preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repam1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p32'
keep if regexm(parm, "^repam*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<37
tempfile tlabor3
save `tlabor3'
restore 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p32'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>36
gen yearstr_l=yearstr-0.2
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tlabor3'

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l , msymbol(Oh) msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: Estimates of ln Labor Force")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "Above Median" 3 "Below Median") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_HL_labor.gph, replace)
 
*Only High

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: Estimates of ln Labor Force")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) leg(off) xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_H_labor.gph, replace)
 
restore

tempfile p1 p2

parmby  "reghdfe ln_value_prod  `repaflexible1' `repaflexible2'    , absorb(year isic $highcontrols) vce(cluster isic)", lab saving(`"`p1'"',replace) idn(1) ids(Unadjusted) 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repam1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p1'
keep if regexm(parm, "^repam*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<37
tempfile tprod3
save `tprod3'
restore 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p1'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>36
gen yearstr_l=yearstr-0.2
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tprod3'

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l ,msymbol(Oh) msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel A: Estimates of ln Value of Production")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "Above Median" 3 "Below Median") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))   saving(flexible_HL_production.gph, replace)
 
*Only High

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) ,  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel A: Estimates of ln Value of Production")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) leg(off)  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))   saving(flexible_H_production.gph, replace)
 
restore

*******
*Triple Difference
*******

*Import industry data
use  "$path/ind_ddd.dta", clear

global highcontrols2 c.ln_value_prod1943#year c.lnlabor_all1943#year 

drop if year==1970

forvalues x=34/69 {
gen ydum19`x'=0
replace ydum19`x'=1 if year==19`x'
}

replace decile_repashare_2=0 if decile_repashare_2==.

replace d2_s=0 if d2_s==.
replace d1_s=0 if d1_s==.

forvalues x=34(1)69{
	gen repam19`x'=ydum19`x'*d2_s
	}

	forvalues x=34(1)69{
	gen repal19`x'=ydum19`x'*finland*d2_s
	}
	
forvalues x=34(1)69{
	gen repan19`x'=ydum19`x'*d1_s
	}

	forvalues x=34(1)69{
	gen repao19`x'=ydum19`x'*finland*d1_s
	}
	
local joku "1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969"

foreach l of local joku {
label var repam`l'  `l'
}

local repaflexible1 "repam1934 repam1935 repam1936 repam1937 repam1938 repam1939 repam1940 repam1941 repam1942  repam1944 repam1945 repam1946 repam1947 repam1948 repam1949 repam1950 repam1951 repam1952 repam1953 repam1954 repam1955 repam1956 repam1957 repam1958 repam1959 repam1960 repam1961 repam1962 repam1963 repam1964 repam1965 repam1966 repam1967 repam1968 repam1969  "

local repaflexible2 "repal1934 repal1935 repal1936 repal1937 repal1938 repal1939 repal1940 repal1941 repal1942  repal1944 repal1945 repal1946 repal1947 repal1948 repal1949 repal1950 repal1951 repal1952 repal1953 repal1954 repal1955 repal1956 repal1957 repal1958 repal1959 repal1960 repal1961 repal1962 repal1963 repal1964 repal1965 repal1966 repal1967 repal1968 repal1969  "

local repaflexible3 "repan1934 repan1935 repan1936 repan1937 repan1938 repan1939 repan1940 repan1941 repan1942  repan1944 repan1945 repan1946 repan1947 repan1948 repan1949 repan1950 repan1951 repan1952 repan1953 repan1954 repan1955 repan1956 repan1957 repan1958 repan1959 repan1960 repan1961 repan1962 repan1963 repan1964 repan1965 repan1966 repan1967 repan1968 repan1969  "

local repaflexible4 "repao1934 repao1935 repao1936 repao1937 repao1938 repao1939 repao1940 repao1941 repao1942  repao1944 repao1945 repao1946 repao1947 repao1948 repao1949 repao1950 repao1951 repao1952 repao1953 repao1954 repao1955 repao1956 repao1957 repao1958 repao1959 repao1960 repao1961 repao1962 repao1963 repao1964 repao1965 repao1966 repao1967 repao1968 repao1969  "

tempfile t1 t2 t3 t4

parmby  "reghdfe ln_value_prod    `repaflexible2'  `repaflexible4' `repaflexible1' `repaflexible3', absorb(year_country isic_country   $highcontrols2) vce(cluster isic_country)", lab saving(`"`t1'"',replace) idn(1) ids(Unadjusted)

parmby  "reghdfe lnlabor_all  `repaflexible2'  `repaflexible4' `repaflexible1' `repaflexible3', absorb(year_country isic_country   $highcontrols2) vce(cluster isic_country)", lab saving(`"`t2'"',replace) idn(1) ids(Unadjusted)

*Production

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t1'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<36
tempfile tprod3
save `tprod3'
restore 

preserve

clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repao1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t1'
keep if regexm(parm, "^repao*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>35&parmseq<71
gen yearstr_l=yearstr-0.4
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tprod3'


twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l , msymbol(Oh) msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel A: DDD Estimates of ln Value of Production")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "Above median exposure" 3 "Below median exposure") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0)) saving(flexible_HL_prod_ddd.gph, replace)
 

*Only high

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) ,  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel A: DDD Estimates of ln Value of Production")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) leg(off) xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_H_prod_ddd.gph, replace)
 
restore

*Production

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t2'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<36
tempfile tlabor3
save `tlabor3'
*title(Panel B: ln Labor Force)
restore 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repao1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t2'
keep if regexm(parm, "^repao*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>35&parmseq<71
gen yearstr_l=yearstr-0.4
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tlabor3'


twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l ,msymbol(Oh) msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: DDD Estimates of ln Labor")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "Above median exposure" 3 "Below median exposure") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_HL_labor_ddd.gph, replace)
 
*Only High

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) ,  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: DDD Estimates of ln Labor")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) leg(off)  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_H_labor_ddd.gph, replace)

restore

graph combine flexible_HL_production.gph   flexible_HL_prod_ddd.gph flexible_HL_labor.gph flexible_HL_labor_ddd.gph , row(2) col(2) iscale(.6) ysize(5) xsize(10) commonscheme  graphregion(fcolor(white) color(white))


graph export "$graphs/combined_flexible_high_low.eps",as(eps)   font(Times) replace
graph export "$graphs/combined_flexible_group_high_low.pdf",as(pdf)   font(Times) replace


graph combine flexible_H_production.gph   flexible_H_prod_ddd.gph flexible_H_labor.gph flexible_H_labor_ddd.gph , row(2) col(2) iscale(.6) ysize(5) xsize(10) commonscheme  graphregion(fcolor(white) color(white))


graph export "$graphs/combined_flexible_high.eps",as(eps)   font(Times) replace
graph export "$graphs/combined_flexible_group_high.pdf",as(pdf)   font(Times) replace


